//
//  CalculateConfig.h
//  JSBasicFramework
//
//  Created by Apple on 2018/8/1.
//  Copyright © 2018年 Apple. All rights reserved.
//

#ifndef CalculateConfig_h
#define CalculateConfig_h

// 根据ip6 屏幕按比例拉升
#define kRealValue(with) ((with)*(SCREEN_WIDTH/375.0f))

/// 苹方极细体
static NSString * PingFangUltralightName = @"PingFangSC-Ultralight";
/// 苹方常规体
static NSString * PingFangRegularName = @"PingFangSC-Regular";
/// 苹方中粗体
static NSString * PingFangSemiboldName = @"PingFangSC-Semibold";
/// 苹方纤细体
static NSString * PingFangThinName = @"PingFangSC-Thin";
/// 苹方细体
static NSString * PingFangLightName = @"PingFangSC-Light";
/// 苹方中黑体
static NSString * PingFangMediumName = @"PingFangSC-Medium";

static NSInteger const kBodyBtnHeight = 48;

static NSInteger const kBodyFontSize  = 16;
static NSInteger const kMediumFontSize  = 14;
static NSInteger const kLowerFontSize  = 12;

static NSInteger const kBodyMargin_10  = 10;

CG_INLINE CGFloat
KREALVALUE(CGFloat oriValue){
    
    return flat(oriValue * ([UIScreen mainScreen].bounds.size.width / 375.0f));
}
//根据文字内容和大小返回 size
CG_INLINE CGSize
JS_LabelSizeWithTextAndFont(NSString *text, UIFont *font){
    CGSize size = [text sizeWithAttributes:@{NSFontAttributeName:font}];
    CGSize newSize = CGSizeMake(size.width, size.height);
    return newSize;
}
//根据文字内容、宽度和字体返回 size
CG_INLINE CGSize
JS_LabelSizeWithTextAndWidthAndFont(NSString *text, CGFloat width, UIFont *font){
    CGSize size = CGSizeMake(width, MAXFLOAT);
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByCharWrapping];
    CGRect frame = [text boundingRectWithSize:size
                                      options:
                    NSStringDrawingTruncatesLastVisibleLine |
                    NSStringDrawingUsesLineFragmentOrigin |
                    NSStringDrawingUsesFontLeading
                                   attributes:@{NSFontAttributeName : font, NSParagraphStyleAttributeName : style} context:nil];
    CGRect newFrame = CGRectMake(frame.origin.x, frame.origin.y, width, frame.size.height);
    return newFrame.size;
}

CG_INLINE CGSize
JS_LabelSizeWithMutableAttributedStringAndWidthAndFont(NSMutableAttributedString *text, CGFloat width, UIFont *font){
    CGSize size = CGSizeMake(width, MAXFLOAT);
    NSMutableParagraphStyle *style = [[NSMutableParagraphStyle alloc] init];
    [style setLineBreakMode:NSLineBreakByCharWrapping];
   
    CGRect frame = [[text copy] boundingRectWithSize:size options:NSStringDrawingTruncatesLastVisibleLine |
                    NSStringDrawingUsesLineFragmentOrigin |
                    NSStringDrawingUsesFontLeading context:nil];
    CGRect newFrame = CGRectMake(frame.origin.x, frame.origin.y, width, frame.size.height);
    return newFrame.size;
}

#endif /* CalculateConfig_h */
